﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using King.Engine.GameObjects;
using Microsoft.Xna.Framework;
using BreacherCreature.Components.Lights;

namespace BreacherCreature.GameObjects
{
    class WallLight : SpriteObject<LightStatus>
    {
        public static int HEIGHT = 100;
        public static int WIDTH = 50;
        private LightCone lightCone;
        public int keyID;

        public SwitchState State;
        private static Dictionary<LightStatus,string> dictionary = new Dictionary<LightStatus, string>()
        {
            {LightStatus.On, "WallLightOn"},
            {LightStatus.Off, "WallLightOff"} 
        };

        public WallLight(int x, int y, Direction direction, bool startState, float radius, int id):
            base(dictionary, DrawDepths.WALL_OBJECT, (startState) ? LightStatus.On : LightStatus.Off)
        {
            keyID = id;
            Bounds = new Rectangle(x, y, WIDTH, HEIGHT);
            Rotation = (float)((int)direction * Math.PI / 2);
            RotationOrigin = new Vector2(0, _texture.Bounds.Height/2);
            State = startState ? SwitchState.On : SwitchState.Off;
            lightCone = new LightCone(radius, Math.PI, Color.White, Vector2.Zero, 25, 25, true)
            {
                TurnedOn = startState,
                RotationOffset = (float)(Math.PI / 2)
            };
            AddComponent(lightCone);
        }

        public WallLight(string x, string y, string direction, string startState, string radius, string id)
            : this(int.Parse(x), int.Parse(y), (Direction)(Enum.Parse(typeof(Direction), direction)), startState == "true", float.Parse(radius), int.Parse(id))
        {

        }

        protected override void UpdateAfterComponents(GameTime gameTime)
        {
            SetSprite((lightCone._flicker.IsOn) ? LightStatus.On : LightStatus.Off);

            base.UpdateAfterComponents(gameTime);

        }
        
    }

    public enum LightStatus
    {
        On,
        Off
    }

    public enum Direction
    {
        Up = 3,
        Down = 1,
        Left = 2,
        Right = 0
    }

}
